package com.ruoyi.web.controller.ddsystem;

import java.util.List;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.system.domain.DdUserRider;
import com.ruoyi.system.service.IDdUserRiderService;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 骑手信息Controller
 * 
 * @author ruoyi
 * @date 2020-02-25
 */
@Controller
@RequestMapping("/system/rider")
public class DdUserRiderController extends BaseController
{
    private String prefix = "system/rider";

    @Autowired
    private IDdUserRiderService ddUserRiderService;

    @RequiresPermissions("system:rider:view")
    @GetMapping()
    public String rider()
    {
        return prefix + "/rider";
    }

    /**
     * 查询骑手信息列表
     */
    @RequiresPermissions("system:rider:list")
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(DdUserRider ddUserRider)
    {
        startPage();
        List<DdUserRider> list = ddUserRiderService.selectDdUserRiderList(ddUserRider);
        return getDataTable(list);
    }

    /**
     * 导出骑手信息列表
     */
    @RequiresPermissions("system:rider:export")
    @Log(title = "骑手信息", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(DdUserRider ddUserRider)
    {
        List<DdUserRider> list = ddUserRiderService.selectDdUserRiderList(ddUserRider);
        ExcelUtil<DdUserRider> util = new ExcelUtil<DdUserRider>(DdUserRider.class);
        return util.exportExcel(list, "rider");
    }

    /**
     * 新增骑手信息
     */
    @GetMapping("/add")
    public String add()
    {
        return prefix + "/add";
    }

    /**
     * 新增保存骑手信息
     */
    @RequiresPermissions("system:rider:add")
    @Log(title = "骑手信息", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(DdUserRider ddUserRider)
    {
        return toAjax(ddUserRiderService.insertDdUserRider(ddUserRider));
    }

    /**
     * 修改骑手信息
     */
    @GetMapping("/edit/{userId}")
    public String edit(@PathVariable("userId") Long userId, ModelMap mmap)
    {
        DdUserRider ddUserRider = ddUserRiderService.selectDdUserRiderById(userId);
        mmap.put("ddUserRider", ddUserRider);
        return prefix + "/edit";
    }

    /**
     * 修改保存骑手信息
     */
    @RequiresPermissions("system:rider:edit")
    @Log(title = "骑手信息", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(DdUserRider ddUserRider)
    {
        return toAjax(ddUserRiderService.updateDdUserRider(ddUserRider));
    }

    /**
     * 删除骑手信息
     */
    @RequiresPermissions("system:rider:remove")
    @Log(title = "骑手信息", businessType = BusinessType.DELETE)
    @PostMapping( "/remove")
    @ResponseBody
    public AjaxResult remove(String ids)
    {
        return toAjax(ddUserRiderService.deleteDdUserRiderByIds(ids));
    }
}
